#include "user_global.h"
#include "modbus.h"


#if FILE_COUNT



// modbus 文件
FILE_DESC files[FILE_COUNT] =
{

};


void Reset_File(uchar fid)
{
    FILE_DESC *f = &files[fid];
    f->count = 0;
}

void Append_File(uchar fid, ushort *rec,ushort n)
{
    FILE_DESC *f = &files[fid];

    while(n--)
        f->ptr.w[f->count++ % f->mask] = *rec++;
}

void Append_File_Word(uchar fid, ushort rec)
{
    FILE_DESC *f = &files[fid];
    f->ptr.w[f->count++ % f->mask] = rec;
}

ushort Read_File(uchar fid, ushort addr)
{
    FILE_DESC *f = &files[fid];
    return f->ptr.w[addr % f->mask];
}

void Write_File(uchar fid, ushort addr, ushort val)
{
    FILE_DESC *f = &files[fid];
    f->ptr.w[addr % f->mask] = from_little_endian_16(val);
}

ushort File_Size(uchar fid)
{
    FILE_DESC *f = &files[fid];
    return f->count;
}

void Set_File_Size(uchar fid, ushort size)
{
    FILE_DESC *f = &files[fid];
    f->count = size;
}

#endif
